home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1991-94 Silicon Graphics, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee, provided
- * that the name of Silicon Graphics may not be used in any advertising or
- * publicity relating to the software without the specific, prior written
- * permission of Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
- * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
- //
- // Sample SceneViewer program.
- // This program reads in a Inventor datafile, and creates a SceneViewer
- // to allow interaction with it.
- //
-
- #include <X11/Intrinsic.h>
- #include <X11/keysym.h>
-
- #include <Inventor/SoDB.h>
- #include <Inventor/SoInteraction.h>
- #include <Inventor/SoPickedPoint.h>
- #include <Inventor/Xt/SoXt.h>
- #include <Inventor/nodekits/SoBaseKit.h>
- #include <Inventor/nodekits/SoNodeKit.h>
- #include <Inventor/nodes/SoSelection.h>
-
- #include "SoSceneViewer.h"
-
- // #define TEST_PICK_CB
- // #define DISABLE_SEL_PICK_MATCH
-
- #ifdef TEST_PICK_CB
- // Test the selection pick callback mechanism
- static SoPath *
- selectionPickCB(void *userData, const SoPickedPoint *pick)
- {
- // Pick the topmost group beneath the selection node
- SoPath *p = pick->getPath();
- SoSelection *sel = (SoSelection *) userData;
-
- // See which child of selection got picked
- int selIndex = -1;
- if (p->getHead() == sel)
- selIndex = 0;
- else {
- for (int i = 1; (selIndex == -1) && (i < p->getLength() - 1); i++)
- if (p->getNode(i) == sel)
- selIndex = i;
- }
-
- // Return a path truncated to this point
- if (selIndex == -1) {
- fprintf(stderr, "SceneViewer selectionPickCB - did not find sel node in pick path!\n");
- return NULL;
- }
-
- return p->copy(selIndex, 2); // 2 nodes, starting at selection node
- }
- #endif
-
- static SbBool
- getArgs(int argc, char **argv, char *&envFile, char *&filename)
- {
- SbBool ok = TRUE;
-
- envFile = NULL;
- filename = NULL;
-
- if (argc == 2) {
- filename = argv[1];
- }
- else if (argc > 2) {
- // see if there is a -e before the file name
- if (strcmp(argv[1], "-e") == 0) {
- envFile = argv[2];
- if (argc > 3)
- filename = argv[3];
- }
- else if (argc == 4) {
- // maybe the -e is after the file name
- if (strcmp(argv[2], "-e") == 0) {
- envFile = argv[3];
- filename = argv[1];
- }
- }
- else ok = FALSE;
- }
-
- return ok;
- }
-
- void main(int argc, char **argv)
- {
- Widget mainWindow;
- SoSceneViewer *sv;
- SoInput in;
- char *envFile, *filename;
-
- // check usage
- if (! getArgs(argc, argv, envFile, filename)) {
- fprintf(stderr, "usage: SceneViewer [-e environ.iv] [file.iv]\n");
- exit( 1 );
- }
-
- // workaround for bug 200909 - this will force OpenGL to create
- // a connection with the X server to receive delete window events
- // (so that OpenGL can delete Accumulation and other software
- // buffers when the window is destroyed).
- if (putenv("GL_CHECK_WINDOW_DESTROY=y"))
- fprintf(stderr, "Could not set the GL_CHECK_WINDOW_DESTROY env.\n");
-
- SbBool useStdin = (filename && strcmp(filename,"-")==0);
-
- // init Inventor
- mainWindow = SoXt::init(argv[0]);
-
- // read the file in, creating a selection node as the root
- // of the scene graph.
- SoSelection *selRoot = new SoSelection;
- selRoot->ref();
- #ifdef TEST_PICK_CB
- selRoot->setPickFilterCallback(selectionPickCB, selRoot);
- #endif
-
- #ifdef DISABLE_SEL_PICK_MATCH
- selRoot->setPickMatching(FALSE);
- #endif
-
- SbBool doRead = FALSE;
- if (useStdin) {
- doRead = TRUE;
- in.setFilePointer(stdin);
- }
- else if (filename) {
- doRead = in.openFile(filename);
- }
-
- if (doRead) {
- fprintf( stderr, "Reading input file...");
- SoNode *n;
- while ((SoDB::read(&in, n) != FALSE) && (n != NULL))
- selRoot->addChild(n);
-
- if ( selRoot->getNumChildren() == 0 )
- fprintf(stderr, "No data read; creating empty scene.\n" );
- else
- fprintf(stderr, "done.\n");
- }
-
- //
- // Create the SceneViewer
- //
- sv = new SoSceneViewer(mainWindow, NULL, TRUE, selRoot, envFile);
- selRoot->unref();
-
- //
- // Build and show the SceneViewer
- //
- sv->show();
- XtRealizeWidget(mainWindow);
-
- //
- // Loop forever
- //
- SoXt::mainLoop();
- }
-